package com.jin.flashsaled.controller;


import com.jin.flashsaled.entity.User;
import com.jin.flashsaled.result.Login;
import com.jin.flashsaled.result.Result;
import com.jin.flashsaled.service.IUserService;
import com.jin.flashsaled.utils.CookieUtil;
import com.jin.flashsaled.utils.MD5Util;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Optional;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    IUserService userService;
    @RequestMapping("/tologin")
    public String login()
    {
        return "login";
    }

    @RequestMapping("/dologin")
    @ResponseBody
    public Result doLogin(Login login, HttpServletResponse response) {

        log.info("用户名={},密码={}", login.getUsername(),login.getPasswordHash());

        return userService.login(login.getUsername(),login.getPasswordHash(),response);

    }



}
